package cn.yuan.xiaoyu.caipumodule.presenter;

import cn.yuan.xiaoyu.caipumodule.activity.CaiPuActivity;
import cn.yuan.xiaoyu.caipumodule.bean.CaiPuListBean;
import cn.yuan.xiaoyu.caipumodule.bean.CaiPuTagListBean;
import cn.yuan.xiaoyu.commonmodule.manager.HttpManager;
import cn.yuan.xiaoyu.commonmodule.net.ResponseListener;

/**
 * Created by yukuoyuan on 2017/2/28.
 * 这是一个菜谱列表的逻辑层
 */

public class CaiPuPresenter {
    ICaiPuView iCaiPuView;
    CaiPuActivity caiPuActivity;

    public CaiPuPresenter(ICaiPuView iCaiPuView, CaiPuActivity caiPuActivity) {
        this.iCaiPuView = iCaiPuView;
        this.caiPuActivity = caiPuActivity;
    }

    /**
     * 获取所有的标签列表
     */
    public void getTagList() {
        HttpManager.getInstance().getCaiPuTagList(new ResponseListener<CaiPuTagListBean>() {
            @Override
            public void onSuccess(CaiPuTagListBean caiPuTagListBean) {
                iCaiPuView.setTagListAdapter(caiPuTagListBean);

            }

            @Override
            public void onFailure(String responseresult) {
                iCaiPuView.showT(responseresult);
                iCaiPuView.closeL();
            }
        });
    }

    /**
     * 获取菜谱列表
     */
    public void getCaiPuList(int page, int tagid) {
        HttpManager.getInstance().getCaiPuList(page, tagid, new ResponseListener<CaiPuListBean>() {
            @Override
            public void onSuccess(CaiPuListBean caiPuListBean) {
                iCaiPuView.setCaipuListAdapter(caiPuListBean);
                iCaiPuView.closeL();
            }

            @Override
            public void onFailure(String responseresult) {
                iCaiPuView.closeL();
                iCaiPuView.showT(responseresult);
            }
        });
    }
}
